import { defineStore } from 'pinia';
// @ts-ignore
import { reactive, ref } from 'vue';
import {getHospitalInfo} from "@/api/hospital";

export const useHospitalStore  = defineStore('hospital', () => {
    const state = reactive({
        name: '',
        address: '',
        hotline: '',
        latitude_val: '',
        longitude_val: '',
        photo: '',
    })

    const handleGetHospital = async () => {
        const {code, data, message} = await getHospitalInfo({})
        if (code === 1) {
            // hospital.name = {...data}
            Object.assign(state, data)
        }
    }

    return {
        ...toRefs(state),
        handleGetHospital
    }
},{
    // persist: true,
    persist: {
        // 默认值，就是使用localStorage
        // storage: localStorage
        // 重写存取方法，转调给UniApp
        storage: {
            getItem(key) {
                // @ts-ignore
                return uni.getStorageSync(key)
            },
            setItem(key, val) {
                // @ts-ignore
                uni.setStorageSync(key, val)
            }
        }
    }
})
